package com.ssm.web;

import com.ssm.Service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "LoginServlet",urlPatterns = "/login")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        String name=request.getParameter("name");
        String password=request.getParameter("password");

        UserService userService=new UserService();

        boolean register = userService.register(name, password);

        response.setContentType("text/html;charset=utf-8");
        if(register){
            //登录成功
            request.getSession().setAttribute("name",name);
            response.sendRedirect(request.getContextPath()+"/");

        }else{
            response.sendRedirect(request.getContextPath()+"/jsp/404.jsp");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
